<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<div class="row">
    <div class="col-lg-12">
        <h3 class="page-header">Chi tiết đơn hàng</h3>
    </div>
    <!-- /.col-lg-12 -->
</div>
<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-body">
                <div class="row">
                    <div class="col-lg-12">
                        <form>            
                            <div class="form-group">                                
                                <button onclick="window.location= '<?php echo $this->baseUrl()."/default/order/list"?>'" type="button" class="btn btn-default">Quay lại</button>                                
                            </div>
                            <div class="col-lg-6">
                                <div class="form-group">
                                    <div class="row">
                                        <div class="col-lg-4">
                                            Mã đơn hàng
                                        </div>
                                        <div class="col-lg-6">
                                            <input type="text" class="form-control" value="<?php echo $this->item->order_no ?>" readonly="true">
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="row">
                                        <div class="col-lg-4">
                                            Tên cửa hàng
                                        </div>
                                        <div class="col-lg-6">
                                            <input type="text" class="form-control" value="<?php echo GlobalLib::getName("agent",$this->item->store_id,'name') ?>" readonly="true">
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="row">
                                        <div class="col-lg-4">
                                            Trạng thái
                                        </div>
                                        <div class="col-lg-6">
                                            <input type="text" class="form-control" value="<?php echo $this->order_status_name ?>" readonly="true">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-6">
                                <div class="form-group">
                                    <div class="row">
                                        <div class="col-lg-4">
                                            Tổng điểm
                                        </div>
                                        <div class="col-lg-6">
                                            <input type="text" class="form-control" value="<?php echo $this->item->total_charges ?>"readonly="true">
                                        </div>
                                    </div>
                                </div>
                                  
                                <div class="form-group">
                                    <div class="row">
                                        <div class="col-lg-4">
                                            Ngày tạo
                                        </div>
                                        <div class="col-lg-6">
                                            <input type="text" class="form-control" value="<?php echo GlobalLib::viewDate($this->item->created)?>"readonly="true">
                                        </div>
                                    </div>
                                </div>                                
                            </div>
                           
                           <div class="row"> 
                               <div class="form-group"> 
                                    <div class="row"></div>
                                </div>  
                           </div> 
                             <div class="form-group"> 
                                    <div class="row">
                                        <div class="col-lg-6">                                            
                                            <?php if($this->item->order_status_id ==1) echo '<button type="button" class="btn btn-default" onclick="return window.location=\''.$this->baseUrl()."/default/order/addorderdetail/id/".$this->item->id.'\';">Thêm chi tiết đơn hàng </button>'; ?>
                                        </div>
                                        
                                    </div>
                                </div>
                            </div>
                    
                            <div class="col-lg-12">
                                <div class="table-reponsive">
                                    <div id="jqxgrid">                        
                                    </div>
                                </div>
                            </div>
                                 
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>   
</div>
<script type="text/javascript">
        $(document).ready(function () {
            // prepare the data
            var source =
            {
                datatype: "json",
                datafields:
                [
                    { name: 'id',type:'int'},
                    { name: 'product_name', type: 'string' },     
                    { name: 'quantity', type: 'string' },
                    { name: 'order_created', type: 'date'},
                    { name:'price',type:'float'},
                    { name:'factor',type:'float'},
                    { name:'charges',type:'float'},
                    { name:'agent_name',type:'string'},
                    {name: 'order_status_name', type:'string'},
                    {name: 'order_status_id', type:'int'}
                ],
                url: "<?php echo $this->baseUrl().'/default/order/servicedetail/order_id/'.$this->item->order_no ?>",
                sortcolumn: 'order_area',
                sortdirection: 'asc'
            };
         var dataAdapter = new $.jqx.dataAdapter(source, {
                loadComplete: function () {
                }
            });
            $("#jqxgrid").jqxDataTable(
            {
                source: dataAdapter,
                theme:'bootstrap',
                pageable: true,
                altRows: true,
                filterable:true,
                sortable: false,                
                width: '100%',                
                ready: function () {
                    $("#jqxgrid").jqxDataTable('hideColumn', 'id');
                },
                columns: [ 
                  { text: 'id',filterable:false,hidden:true,dataField:'id',cellsalgin:'right',width:0},
                  { text: 'order_status_id',filterable:false,hidden:true,dataField:'order_status_id',cellsalgin:'right',width:0},
                  { text: 'Tên sản phẩm',hidden:false,dataField:'product_name',cellsalgin:'right',width:'20 %'},
                  { text: 'Ngày mua hàng',hidden:false,dataField:'order_created',cellsalgin:'right',width:'15%',cellsFormat: 'dd-MM-yyyy'},                  
                  { text: 'Số lượng',hidden:false,dataField:'quantity',cellsalgin:'right',width:'10%'},                  
                  { text: 'Tên đại lý',hidden:false,editable: false, dataField: 'agent_name', width: '15%' },
                  { text: 'Số điểm', editable: false, dataField: 'factor', width:'10%' },
                  { text: 'Số điểm nhận được', editable: false, dataField: 'charges', width:'15%' },
                  { text: 'Trạng thái', editable: false, dataField: 'order_status_name', width:'10%' },
                   {
                    text: 'Sửa', cellsAlign: 'center', align: "center", width:'5%' ,columnType: 'none', editable: false, sortable: false, dataField: null, cellsRenderer: function (row, column, value) {
                          editrow = row;
                          var dataRecord = $("#jqxgrid").jqxDataTable('getRows');
                          if(dataRecord[editrow]['id']===null){
                              url="";
                              return url;
                          } else { 
                               var url="";
                               if(dataRecord[editrow]['order_status_id']!=1) return url;
                               else
                               {
                                url= "<div style='overflow: hidden; text-overflow: ellipsis; padding-bottom: 2px; text-align: center; margin-right: 2px; margin-left: 4px; margin-top: 4px;'><a class='fa fa-edit fa-lg'";
                                url = url + "href='<?php echo $this->baseUrl()?>/default/order/editorderdetail/id/"+dataRecord[editrow]['id']+"'></a></div>";
                                }
                               return url;
                          }
                      }
                  }
                ]
            });
           
        });
    </script>
    <script type="text/javascript">        
        function check()
        {
           window.location = "<?php echo $this->baseUrl().'/default/order/orderbrowser/id/'.$this->item->id ?>";  
        };
        function check1()
        {
           window.location = "<?php echo $this->baseUrl().'/default/order/ordercancel/id/'.$this->item->id ?>";  
        };
    </script>